package edu.sctu.practice.class02.hujie.my_practice.day20151119collection;

import java.util.HashSet;
import java.util.Set;

/**
 * 学生类
 * Created by hp on 2015/11/19.
 */
public class Student implements Comparable<Student>{
    public String id;
    public String name;
    public Set<Course> course;

    //构造器
    public Student(String id, String name) {
        this.id = id;
        this.name = name;
        this.course = new HashSet<Course>();//此处倒入包
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((name == null) ? 0 : name.hashCode());
        return result;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj == null) {
            return false;
        }
        if (!(obj instanceof Course)) {
            return false;
        }
        Course course = (Course) obj;
        if (this.name == null) {
            if (course.name == null)
                return true;
            else
                return false;
        } else {
            if (this.name.equals(course.name))
                return true;
            else
                return false;
        }

    }

    @Override
    public int compareTo(Student o) {
        return this.id.compareTo(o.id);
    }
}
